<template>
  <div class="main-salesChart" ref="salesRef" />
</template>

<script lang="ts">
export default {
  name: "salesChart",
};
</script>

<script lang="ts" setup>
import * as echarts from "echarts";
import { watch, ref } from "vue";
const salesRef = ref();
const props = defineProps<{
  data: number[];
  axis: string[];
  title: string;
}>();
watch(
  () => props.data,
  () => {
    const myChart = echarts.init(salesRef.value);
    myChart.setOption({
      title: {
        text: props.title,
        textStyle: {
          fontSize: 14,
        },
        top: 20,
      },
      xAxis: {
        data: props.axis,
      },
      yAxis: {},
      tooltip: {},
      grid: {
        bottom: 20,
        left: 40,
        right: 40,
      },
      series: {
        type: "bar",
        data: props.data,
        barWidth: 20,
      },
    });
  }
);
</script>

<style scoped>
.main-salesChart {
  width: 100%;
  height: 300px;
}
</style>
